<!-- 通讯设置 -->
<template>
    <div> <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="ip：" prop="ip">
                <el-input type="" v-model="ruleForm.ip"></el-input>
            </el-form-item>
            <el-form-item label="端口号：" prop="port">
                <el-input type="text" v-model.number="ruleForm.port"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>

            </el-form-item>
        </el-form>
        <div class="zezaoc">
            <Btn_box />
        </div>
        <div class="wrungMask" v-show="warnIsbool">
            <i class="el-icon-warning" />

        </div>
        <div class="lod" v-show="elIconWarningBool">
            <lodFile :doScTitle="doScTitle" />
        </div>
    </div>
</template>
<script>
import { commmunifunEdit, ObtainModifiedRequests } from "@/api/SettingsApi/index.js"
import Btn_box from "@/components/uponelevel/index.vue"
export default {
    components: {
        Btn_box,
        lodFile: () => import("@/components/outfilelod/index.vue"),
    },
    data() {

        var validateip = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请输入IP地址'));
            } else {
                if (/^(((25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))$/
                    .test(value)) {
                    callback();
                } else {
                    callback(new Error('请输入正确的ip地址'));

                }
            }
        };

        var validateport = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请输入端口号'));
            } else {
                callback();
            }
        };
        return {
            elIconWarningBool: false,
            doScTitle: "",
            wrungTitle: "",
            warnIsbool: false,
            userdata: "",
            item3:"",
            ruleForm: {
                ip: '',
                port: "",
                type: true
            },
            rules: {
                ip: [
                    { validator: validateip, trigger: 'blur' }
                ],
                port: [
                    { validator: validateport, trigger: 'blur' }
                ],

            }
        };
    },

    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {

                    let data = {
                        equipmentId: this.$store.state.UserIndex.equipment.equipmentId,
                        modbusIp: this.ruleForm.ip,
                        modbusPort: this.ruleForm.port,
                    };
                    commmunifunEdit(data).then(res => {
                        if (res.code !== 200) {

                            this.doScTitle = res.msg;
                            this.elIconWarningBool = true
                            clearInterval(this.time3)
                            this.time3 = setInterval(() => {
                                this.elIconWarningBool = false
                            }, 3000)
                           

                        }
                    })
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },

    },
    mounted() {
        ObtainModifiedRequests({
            id: this.$store.state.UserIndex.equipment.equipmentId
        }).then(res => {
            console.log(res.data);
            if (res.code == 200) {
                this.ruleForm.ip = res.data.modbusIp
                this.ruleForm.port = res.data.modbusPort
            } else {
                this.wrungTitle = res.msg;
            }

        })
    }
}
</script>
<style lang="less" scoped>
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.lod {
    position: fixed;
    top: 5%;
    left: 42%;
    z-index: 999;

}

.el-input {
    height: 100%;
}


::-webkit-scrollbar {
    list-style: none;
}

.wrungMask {
    width: 390px;

    background: rgba(45, 36, 62);
    color: rgb(150, 84, 94);
    text-align: center;
    line-height: 51px;
    overflow: auto;
    // border: 0.44px solid #ffd4d4;
    border-radius: 3px;
    font-family: "思源黑体", "Microsoft YaHei";
    font-weight: 400;

}

.zezaoc {
    width: 106px;
    height: 30px;
    position: fixed;
    font-size: 10px;
    top: 80px;
    left: 1770px;

    display: flex;
    cursor: pointer;

    div {
        width: 98.38px;
        height: 40.38px;
        background: #031231;
        opacity: 1;
        text-align: center;
        line-height: 40.38px;
        color: white;
        margin: 0px 5px;

    }


}



.el-form-item_content {
    margin-left: 24px !important;
}

.title {
    width: 63px;
    height: 31px;

}

.el-form {
    padding: 43px;
}

.checkitem {
    width: 19px !important;
    height: 19px !important;
    opacity: 1;
    border: 1px solid #5B9FC3 !important;
    position: fixed;
    top: 126px;
    left: 296px;
}



.el-form-item /deep/ .el-form-item__label {
    color: white !important;
    font-size: 15px;
}

.el-color-picker__icon,
.el-input,
.el-textarea {
    width: 15% !important;
}

.el-input /deep/ .el-input__inner {
    width: 225px;
    height: 27px;
    background: #031231;
    opacity: 1;
    border: 0.4px solid #5ca0c3;
    color: white;
    border-radius: 0px;
}

.el-button--primary {
    width: 136px;
    height: 30px;
    line-height: 4px;

    background: #00184B;
    border: 1px solid #113D71;
    background: none;
    color: white;
    border-radius: 0px;
    background: #00184B;
    cursor: pointer;
}

.phone_margin_box {
    width: 20px;
    height: 20px;
    border: 1px solid #5B9FC3;
    margin-top: 10px;
}

.phone_padding_box {
    width: 10px;
    height: 10px;
    border: 2px solid #031231;
    background: #5B9FC3;
    margin: 3px;

}

.el-checkbox-group {
    display: flex;
}

.phone_padding_box_false {
    width: 10px;
    height: 10px;
    border: 2px solid #031231;
    background: #031231;
    margin: 3px;
}
</style>
